package com.xique.park.service.biz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xique.common.core.constant.Constants;
import com.xique.common.core.utils.AliossUtil;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.park.bean.domain.*;
import com.xique.park.bean.dto.ParkInOutDelDto;
import com.xique.park.bean.dto.ParkOutDto;
import com.xique.park.bean.request.app.ParkInAndOutListRequest;
import com.xique.park.bean.request.app.ParkInOutPicRequest;
import com.xique.park.bean.request.web.parkInAndOut.WebParkInAndOutDetailRequest;
import com.xique.park.bean.request.web.parkInAndOut.WebParkInAndOutListRequest;
import com.xique.park.bean.transform.web.parkInAndOut.*;
import com.xique.park.bean.vo.app.ParkInAndOutVo;
import com.xique.park.bean.vo.app.ParkInOutPicVo;
import com.xique.park.bean.vo.web.parkInAndOut.ParkInAndOutWebVo;
import com.xique.park.bean.vo.web.parkInAndOut.ParkInOutDelVo;
import com.xique.park.bean.vo.web.parkInAndOut.detail.*;
import com.xique.park.mapper.ParkInMapper;
import com.xique.park.mapper.ParkOutMapper;
import com.xique.park.mapper.biz.ParkInAndOutMapper;
import com.xique.park.service.biz.service.IParkInOutBizService;
import com.xique.park.service.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 进出记录
 *
 * @author xique
 */
@Slf4j
@Service
public class ParkInOutBizServiceImpl implements IParkInOutBizService {

    @Resource
    private ParkInAndOutMapper parkInAndOutMapper;

    @Resource
    private ParkInMapper parkInMapper;

    @Resource
    private ParkOutMapper parkOutMapper;

    @Autowired
    private AliossUtil aliossUtil;

    @Autowired
    private IPayOrderService payOrderService;

    @Autowired
    private IParkCouponPpService parkCouponPpService;

    @Autowired
    private IParkLaneService parkLaneService;

    @Autowired
    private IParkCarMngtypeService parkCarMngtypeService;

    @Autowired
    private IParkOutService parkOutService;

    @Autowired
    private IParkInService parkInService;

    @Autowired
    private IParkInfoService parkInfoService;

    @Autowired
    private IParkingOrderService parkingOrderService;

    @Autowired
    private IParkOutCopyService parkOutCopyService;

    @Autowired
    private IParkInCopyService parkInCopyService;

    @Autowired
    private IParkConfigService parkConfigService;

    /**
     * APP移动端进场和出场记录
     */
    @Override
    public AjaxResult getParkInAndOutList(ParkInAndOutListRequest request) {
        Page<ParkInAndOutVo> page = new Page<>();
        page.setCurrent(request.getPageNum());
        page.setSize(request.getPageSize());
        request.setParkId(SecurityUtils.getParkId());
        IPage<ParkInAndOutVo> pageResult = parkInAndOutMapper.findByPage(page, request);
        List<ParkInAndOutVo> parkInAndOutVoList = pageResult.getRecords();
        Map<String, Object> map = new HashMap<>(2);
        map.put(Constants.LIST, parkInAndOutVoList);
        map.put(Constants.TOTAL, pageResult.getTotal());
        return AjaxResult.success(map);
    }

    @Override
    public AjaxResult getPic(ParkInOutPicRequest request) {
        if (StringUtils.isEmpty(request.getType())) {
            return AjaxResult.error("进出场类型不能为空");
        }
        if (StringUtils.isNull(request.getRecordId())) {
            return AjaxResult.error("记录ID不能为空");
        }
        if ("in".equals(request.getType())) {
            ParkIn parkIn = parkInMapper.selectById(request.getRecordId());
            if (null != parkIn) {
                String inPicObjectName = parkIn.getInPic();
                String picUrl = StringUtils.isNotEmpty(inPicObjectName) ? aliossUtil.getJzyGetObjectUrl(inPicObjectName).toString() : "";
                ParkInOutPicVo vo = new ParkInOutPicVo();
                vo.setPicUrl(picUrl);
                vo.setPlate(parkIn.getInCarPlate());
                vo.setRecordId(parkIn.getId());
                return AjaxResult.success(vo);
            } else {
                return AjaxResult.error("未查询到入场记录");
            }
        } else if ("out".equals(request.getType())) {
            ParkOut parkOut = parkOutMapper.selectParkOutById(request.getRecordId());
            if (null != parkOut) {
                String outPicObjectName = parkOut.getOutPic();
                String picUrl = StringUtils.isNotEmpty(outPicObjectName) ? aliossUtil.getJzyGetObjectUrl(outPicObjectName).toString() : "";
                ParkInOutPicVo vo = new ParkInOutPicVo();
                vo.setPicUrl(picUrl);
                vo.setPlate(parkOut.getOutCarPlate());
                vo.setRecordId(parkOut.getId());
                return AjaxResult.success(vo);
            } else {
                return AjaxResult.error("未查询到出场记录");
            }
        } else {
            return AjaxResult.error("不支持的进出场类型");
        }
    }

    @Override
    public AjaxResult getWebParkInAndOutList(WebParkInAndOutListRequest request) {
        Page<ParkInAndOutWebVo> page = new Page<>();
        page.setCurrent(request.getPageNum());
        page.setSize(request.getPageSize());
        request.setParkId(SecurityUtils.getParkId());
        // 查询ID
        IPage<ParkInAndOutWebVo> pageResult = parkInAndOutMapper.webFindByPage(page, request);
        List<ParkInAndOutWebVo> parkInAndOutWebVoPageList = pageResult.getRecords();

        List<ParkInAndOutWebVo> parkInAndOutWebVoList = new ArrayList<>();
        if (CollUtil.isNotEmpty(parkInAndOutWebVoPageList)) {
            // 根据ID查询具体信息
            List<Long> parkInIds = new ArrayList<>();
            parkInAndOutWebVoPageList.forEach(parkInAndOutWebVo -> parkInIds.add(parkInAndOutWebVo.getId()));
            parkInAndOutWebVoList = parkInAndOutMapper.batchSelectIds(parkInIds, request);
        }

        List<ParkInAndOutWebVo> resultList = duplicateRemoval(parkInAndOutWebVoList);

        Map<String, Object> map = new HashMap<>(2);
        map.put(Constants.LIST, resultList);
        map.put(Constants.TOTAL, pageResult.getTotal());
        return AjaxResult.success(map);
    }

    private List<ParkInAndOutWebVo> duplicateRemoval(List<ParkInAndOutWebVo> parkInAndOutWebVoList) {
        ParkInAndOutWebVo[] parkInAndOutArray = new ParkInAndOutWebVo[200];
        if (CollUtil.isNotEmpty(parkInAndOutWebVoList)) {
            Map<Long, Integer> indexMap = new HashMap<>(parkInAndOutWebVoList.size());
            Map<Long, Date> outTimeMap = new HashMap<>(parkInAndOutWebVoList.size());

            for (int i = 0; i < parkInAndOutWebVoList.size(); i++) {
                ParkInAndOutWebVo parkInAndOut = parkInAndOutWebVoList.get(i);
                Long inId = parkInAndOut.getInId();
                if (null != inId) {
                    Integer indexExist = indexMap.get(inId);
                    if (null == indexExist) {
                        indexMap.put(inId, i);
                        outTimeMap.put(inId, parkInAndOut.getOutTime());
                        parkInAndOutArray[i] = parkInAndOut;
                    } else {
                        // 已经存在相同的进场记录信息，则判断出场时间，取最新的一条
                        Date dateExist = outTimeMap.get(inId);
                        Date dateNew = parkInAndOut.getOutTime();
                        if (dateNew.after(dateExist)) {
                            parkInAndOutArray[indexExist] = parkInAndOut;
                        }
                    }
                }
            }

            parkInAndOutArray = ArrayUtil.removeNull(parkInAndOutArray);
            List<ParkInAndOutWebVo> resultList = new ArrayList<>();
            Collections.addAll(resultList, parkInAndOutArray);
            return resultList;
        }
        return ListUtil.empty();
    }

    @Override
    public AjaxResult getWebParkInAndOutDetail(WebParkInAndOutDetailRequest request) {
        long parkId = SecurityUtils.getParkId();

        ParkIn parkIn = null;
        if (StringUtils.isNotNull(request.getInId())) {
            parkIn = parkInMapper.selectParkInById(request.getInId());
        }

        ParkInDetailVo parkInDetailVo = null;
        List<PayOrder> orderList = new ArrayList<>();
        List<ParkCouponPp> couponList = new ArrayList<>();

        if (null != parkIn) {
            String inPicUrl = StringUtils.isNotEmpty(parkIn.getInPic()) ? aliossUtil.getJzyGetObjectUrl(parkIn.getInPic()).toString() : "";
            parkInDetailVo = ParkInAndOutTransform.parkInTransformDetailVo(parkIn, inPicUrl);

            Long inLaneId = parkInDetailVo.getInLaneId();
            if (null != inLaneId) {
                ParkLane parkLane = parkLaneService.selectParkLaneById(inLaneId);
                if (null != parkLane) {
                    parkInDetailVo.setInLaneName(parkLane.getName());
                }
                long mngTypeId = parkInDetailVo.getMngTypeId();
                ParkCarMngtype parkCarMngtype = parkCarMngtypeService.selectParkCarMngtypeById(mngTypeId);
                if (null != parkCarMngtype) {
                    parkInDetailVo.setMngTypeName(parkCarMngtype.getName());
                }
            }

            // 支付记录
            PayOrder payOrder = new PayOrder();
            payOrder.setParkId(parkId);
            payOrder.setParkingSerial(parkIn.getParkingSerial());
            payOrder.setPlate(parkIn.getInCarPlate());
            orderList = payOrderService.selectTPayOrderList(payOrder);

            // 优惠券记录
            ParkCouponPp parkCouponPp = new ParkCouponPp();
            parkCouponPp.setParkId(parkId);
            parkCouponPp.setParkingSerial(parkIn.getParkingSerial());
            parkCouponPp.setPlate(parkIn.getInCarPlate());
            couponList = parkCouponPpService.selectParkCouponPpList(parkCouponPp);
        }

        ParkOut parkOut = null;
        if (StringUtils.isNotNull(request.getOutId())) {
            parkOut = parkOutMapper.selectParkOutById(request.getOutId());
        }

        ParkOutDetailVo parkOutDetailVo = null;
        ParkOrderDetailVo parkOrderDetailVo = new ParkOrderDetailVo();
        if (null != parkOut) {
            String outPicUrl = StringUtils.isNotEmpty(parkOut.getOutPic()) ? aliossUtil.getJzyGetObjectUrl(parkOut.getOutPic()).toString() : "";

            parkOutDetailVo = ParkInAndOutTransform.parkOutTransformDetailVo(parkOut, outPicUrl);
            Long onLaneId = parkOutDetailVo.getOutLaneId();
            ParkLane parkLane = parkLaneService.selectParkLaneById(onLaneId);
            if (null != parkLane) {
                parkOutDetailVo.setOutLaneName(parkLane.getName());
            }
            Long mngTypeId = parkOutDetailVo.getMngTypeId();
            if (mngTypeId != null) {
                ParkCarMngtype parkCarMngtype = parkCarMngtypeService.selectParkCarMngtypeById(mngTypeId);
                if (null != parkCarMngtype) {
                    parkOutDetailVo.setMngTypeName(parkCarMngtype.getName());
                }
            }

            if (parkOut.getStopTime() == null || parkOut.getStopTime() == 0) {
                // 计算停车时长
                Date outTime = parkOut.getOutTime();
                if (null != parkIn && parkIn.getInTime() != null && outTime != null) {
                    Date inTime = parkIn.getInTime();
                    long stopTime = DateUtil.between(inTime, outTime, DateUnit.SECOND);
                    parkOut.setStopTime(stopTime);
                }
            }

            parkOrderDetailVo = ParkInAndOutTransform.parkOutTransformParkOrderDetailVo(parkOut);
        }

        List<PayOrderDetailVo> payOrderDetailVoList = new ArrayList<>(orderList.size());
        if (CollectionUtils.isNotEmpty(orderList)) {
            orderList.forEach(item -> {
                // 更新停车券减免金额，支付记录中的金额是错误的，暂时只能去出场记录里面取
                String parkingSerial = item.getParkingSerial();
                if (StrUtil.isNotBlank(parkingSerial)) {
                    List<ParkOutDto> parkOutDtoList = parkOutService.selectParkOutByParkingSerial(parkId, parkingSerial);
                    if (CollUtil.isNotEmpty(parkOutDtoList)) {
                        item.setReduceFee(parkOutDtoList.get(0).getReduceFee().longValue());
                    }
                }
                PayOrderDetailVo vo = ParkInAndOutTransform.payOrderTransformPayOrderDetailVo(item);
                payOrderDetailVoList.add(vo);
            });
        }

        List<ParkCouponDetailVo> parkCouponDetailVoList = new ArrayList<>(couponList.size());
        if (CollectionUtils.isNotEmpty(couponList)) {
            ParkOrderDetailVo finalParkOrderDetailVo = parkOrderDetailVo;
            couponList.forEach(item -> {
                ParkCouponDetailVo vo = ParkInAndOutTransform.couponTransformCouponDetailVo(item);
                vo.setTotalFee(finalParkOrderDetailVo.getTotalFee());
                vo.setMayFee(finalParkOrderDetailVo.getMayFee());
                vo.setReduceFee(finalParkOrderDetailVo.getReduceFee());
                vo.setActualFee(finalParkOrderDetailVo.getActualFee());
                parkCouponDetailVoList.add(vo);
            });
        }

        ParkInAndOutDetailWebVo parkInAndOutDetailWebVo = new ParkInAndOutDetailWebVo();
        parkInAndOutDetailWebVo.setParkInDetailVo(parkInDetailVo);
        parkInAndOutDetailWebVo.setParkOutDetailVo(parkOutDetailVo);
        parkInAndOutDetailWebVo.setParkOrderDetailVo(parkOrderDetailVo);
        parkInAndOutDetailWebVo.setPayOrderDetailVo(payOrderDetailVoList);
        parkInAndOutDetailWebVo.setParkCouponPpList(parkCouponDetailVoList);
        return AjaxResult.success(parkInAndOutDetailWebVo);
    }

    /**
     * 定时删除进出记录
     */
    @Override
    public void delete() {
        // 查找所有的车场
        List<ParkInfo> parkInfoList = getAllParkInfo();

        if (CollUtil.isNotEmpty(parkInfoList)) {
            parkInfoList.forEach(parkInfo -> {
                long parkId = parkInfo.getId();
                long startTime = System.currentTimeMillis();
                log.info("[进出记录]-定时删除进出记录，开始处理：{},{}", parkId, parkInfo.getName());
                // 分页查询进出记录，删除
                getParkInAndOutBeforeDay(parkId);
                log.info("[进出记录]-定时删除进出记录，处理完成：{},{},耗时{}秒", parkId, parkInfo.getName(), (System.currentTimeMillis() - startTime) / 1000);
            });
        }
    }

    @Override
    public void deleteByParkId(Long parkId) {
        long startTime = System.currentTimeMillis();
        log.info("[进出记录]-根据项目ID删除进出记录，开始处理：{}", parkId);
        // 分页查询进出记录，删除
        getParkInAndOutBeforeDay(parkId);
        log.info("[进出记录]-根据项目ID删除进出记录，处理完成：{},耗时{}秒", parkId, (System.currentTimeMillis() - startTime) / 1000);
    }

    private void getParkInAndOutBeforeDay(Long parkId) {
        // 查询车辆的进出记录保存时间
        ParkConfig parkConfig = parkConfigService.selectParkConfigByParkId(parkId);
        if (parkConfig == null) {
            log.warn("[进出记录]-定时删除进出记录，车场参数为空：{}", parkId);
            return;
        }

        String config = parkConfig.getConfig();
        if (StrUtil.isBlank(config)) {
            log.warn("[进出记录]-定时删除进出记录，车场全局参数为空：{}", parkId);
            return;
        }

        JSONObject configObj = JSON.parseObject(config);
        Integer dateSaveDay = configObj.getInteger("dataSaveDays");
        if (null == dateSaveDay) {
            log.warn("[进出记录]-定时删除进出记录，进出记录保存时间为空：{}", parkId);
            return;
        }

        log.info("[进出记录]-定时删除进出记录，删除前{}天的进出记录：{}", dateSaveDay, parkId);

        int beforeDay = -dateSaveDay - 1;
        DateTime beforeDate = DateUtil.offsetDay(new Date(), beforeDay);
        String beforeDateStr = DateUtil.formatDate(beforeDate);

        // 获取需要删除的日期
        List<String> delDateList = parkOutService.selectDeleteDate(parkId, beforeDateStr);
        if (CollUtil.isNotEmpty(delDateList)) {
            delDateList.forEach(delData -> {
                // 根据日期查询当日有多少条记录
                Long count = selectDeleteCount(parkId, delData);
                if (null != count && 0 != count) {
                    // 查询待删除的进出记录
                    ParkInOutDelVo parkInOutDelVo = selectDelInOut(parkId, delData);

                    // 将进出记录中的信息写入订单中
                    updateParkingOrder(parkId, delData, parkInOutDelVo);

                    // 备份进出记录
                    backupsInOutRecord(parkId, delData, parkInOutDelVo);

                    // 删除进出记录
                    Set<Long> delInIdSet = parkInOutDelVo.getDelInIdSet();
                    Set<Long> delOutIdSet = parkInOutDelVo.getDelOutIdSet();
                    deleteParkInAndParkOut(delInIdSet, delOutIdSet);
                }
            });
        }
    }

    /**
     * 备份进出记录
     */
    private void backupsInOutRecord(Long parkId, String delData, ParkInOutDelVo parkInOutDelVo) {
        long startTime = System.currentTimeMillis();
        log.info("[进出记录]-定时删除进出记录，备份进出记录，开始备份，parkId：{},delData:{}", parkId, delData);

        Set<Long> delOutIdSet = parkInOutDelVo.getDelOutIdSet();
        if (CollUtil.isNotEmpty(delOutIdSet)) {
            List<ParkOut> parkOutList = parkOutService.getBaseMapper().selectBatchIds(new ArrayList<>(delOutIdSet));
            if (CollUtil.isNotEmpty(parkOutList)) {
                List<ParkOutCopy> parkOutCopyList = new ArrayList<>();
                parkOutList.forEach(parkOut -> {
                    ParkOutCopy parkOutCopy = BeanUtil.copyProperties(parkOut, ParkOutCopy.class);
                    parkOutCopyList.add(parkOutCopy);
                });
                // 批量新增出场的备份
                parkOutCopyService.saveBatch(parkOutCopyList);
            }
        }

        Set<Long> delInSet = parkInOutDelVo.getDelInIdSet();
        if (CollUtil.isNotEmpty(delInSet)) {
            List<ParkIn> parkInList = parkInService.getBaseMapper().selectBatchIds(new ArrayList<>(delInSet));
            if (CollUtil.isNotEmpty(parkInList)) {
                List<ParkInCopy> parkInCopyList = new ArrayList<>();
                parkInList.forEach(parkIn -> {
                    ParkInCopy parkInCopy = BeanUtil.copyProperties(parkIn, ParkInCopy.class);
                    parkInCopyList.add(parkInCopy);
                });
                // 批量新增入场的备份
                parkInCopyService.saveBatch(parkInCopyList);
            }
        }

        log.info("[进出记录]-定时删除进出记录，备份进出记录，备份完成，parkId：{},delData:{},耗时：{}秒", parkId, delData, (System.currentTimeMillis() - startTime) / 1000);
    }

    /**
     * 将进出记录中的信息写入订单中
     */
    private void updateParkingOrder(Long parkId, String delData, ParkInOutDelVo parkInOutDelVo) {
        long startTime = System.currentTimeMillis();
        log.info("[进出记录]-定时删除进出记录，将进出记录中的信息写入订单中，开始更新，parkId：{},delData:{}", parkId, delData);

        List<ParkInOutDelDto> parkInOutDelDtoList = parkInOutDelVo.getParkInOutDelDtoList();
        if (CollUtil.isNotEmpty(parkInOutDelDtoList)) {
            List<ParkingOrder> parkingOrderList = new ArrayList<>();

            parkInOutDelDtoList.forEach(parkInOutDelDto -> {

                String parkingSerial = parkInOutDelDto.getParkingSerial();
                if (null != parkId && StrUtil.isNotBlank(parkingSerial)) {
                    ParkingOrder parkingOrder = new ParkingOrder();
                    parkingOrder.setParkId(parkId);
                    parkingOrder.setParkingSerial(parkingSerial);

                    parkingOrder.setInCarPlate(parkInOutDelDto.getInCarPlate());
                    parkingOrder.setInTime(parkInOutDelDto.getInTime());
                    parkingOrder.setInPic(parkInOutDelDto.getInPic());
                    parkingOrder.setInLaneName(parkInOutDelDto.getInLaneName());
                    parkingOrder.setInType(parkInOutDelDto.getInType());
                    parkingOrder.setInStatus(parkInOutDelDto.getInStatus());
                    parkingOrder.setInRemark(parkInOutDelDto.getInRemark());
                    parkingOrder.setInUpdateUser(parkInOutDelDto.getInUpdateUser());
                    parkingOrder.setCarMngtypeName(parkInOutDelDto.getCarMngtypeName());
                    parkingOrder.setOutCarPlate(parkInOutDelDto.getOutCarPlate());
                    parkingOrder.setOutTime(parkInOutDelDto.getOutTime());
                    parkingOrder.setOutPic(parkInOutDelDto.getOutPic());
                    parkingOrder.setOutLaneName(parkInOutDelDto.getOutLaneName());
                    parkingOrder.setOutType(parkInOutDelDto.getOutType());
                    parkingOrder.setOutStatus(parkInOutDelDto.getOutStatus());
                    parkingOrder.setOutRemark(parkInOutDelDto.getOutRemark());
                    parkingOrder.setOutUpdateUser(parkInOutDelDto.getOutUpdateUser());

                    parkingOrderList.add(parkingOrder);
                }
            });

            if (CollUtil.isNotEmpty(parkingOrderList)) {
                parkingOrderService.updateBatchByParkIdAndParkingSerial(parkingOrderList);
            }
        }
        log.info("[进出记录]-定时删除进出记录，将进出记录中的信息写入订单中，更新完成，parkId：{},delData:{},耗时：{}秒", parkId, delData, (System.currentTimeMillis() - startTime) / 1000);
    }

    /**
     * 删除进出记录
     *
     * @param inIdSet  入场记录ID集合
     * @param outIdSet 出场记录ID集合
     */
    private void deleteParkInAndParkOut(Set<Long> inIdSet, Set<Long> outIdSet) {
        long startTime = System.currentTimeMillis();
        log.info("[进出记录]-定时删除进出记录，开始删除，inIdSet：{},outIdSet:{}", inIdSet, outIdSet);
        if (CollUtil.isNotEmpty(inIdSet)) {
            if (inIdSet.size() >= 10000) {
                parkInService.batchDel(inIdSet);
            } else {
                Long[] inIdArray = inIdSet.toArray(new Long[0]);
                parkInService.deleteParkInByIds(inIdArray);
            }
        }
        if (CollUtil.isNotEmpty(outIdSet)) {
            if (outIdSet.size() >= 10000) {
                parkOutService.batchDel(outIdSet);
            } else {
                Long[] outIdArray = outIdSet.toArray(new Long[0]);
                parkOutService.deleteParkOutByIds(outIdArray);
            }
        }
        log.info("[进出记录]-定时删除进出记录，删除完成，inIdSet：{},outIdSet:{},耗时：{}", inIdSet, outIdSet, (System.currentTimeMillis() - startTime) / 1000);
    }

    /**
     * 查询待删除的进出记录
     *
     * @param parkId  车场ID
     * @param delData 删除的日期
     */
    private ParkInOutDelVo selectDelInOut(Long parkId, String delData) {
        // 待删除的进出记录ID
        Set<Long> delInIdSet = new HashSet<>();
        Set<Long> delOutIdSet = new HashSet<>();

        List<ParkInOutDelDto> parkInOutDelDtoList = parkOutService.selectParkInAndOutList(parkId, delData);
        parkInOutDelDtoList.forEach(parkInOutDelDto -> {
            delInIdSet.add(parkInOutDelDto.getInId());
            delOutIdSet.add(parkInOutDelDto.getOutId());
        });

        return ParkInOutDelVo.builder().delInIdSet(delInIdSet).delOutIdSet(delOutIdSet).parkInOutDelDtoList(parkInOutDelDtoList).build();
    }

    /**
     * 获取需要删除的总行数
     *
     * @param parkId  车场ID
     * @param delData 删除的日期
     */
    private Long selectDeleteCount(Long parkId, String delData) {
        return parkOutService.selectDeleteCount(parkId, delData);
    }

    /**
     * 获取所有的项目信息
     */
    private List<ParkInfo> getAllParkInfo() {
        return parkInfoService.selectAll();
    }

}
